﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SetModel : MonoBehaviour {
    EginUser user = EginUser.Instance;
    public GameObject musicClose;
    public GameObject musicOpen;
    public GameObject effectclose;
    public GameObject effectOpen;
    public GameObject CloseBtn;
    public UISprite avatar;
    public UITexture wxAvatar;
    public UILabel IDLabel;
    private void Awake()
    {
        UIEventListener.Get(musicClose).onClick = ButtonClick;
        UIEventListener.Get(musicOpen).onClick = ButtonClick;
        UIEventListener.Get(effectclose).onClick = ButtonClick;
        UIEventListener.Get(effectOpen).onClick = ButtonClick;
        UIEventListener.Get(CloseBtn).onClick = ButtonClick;
        Debug.Log(user.effectMusic);
        if (user.bgMusic)
        {
            musicClose.SetActive(false);
            musicOpen.SetActive(true);
        }
        else {
            musicOpen.SetActive(false);
            musicClose.SetActive(true);
        }
        if (user.effectMusic)
        {
            effectclose.SetActive(false);
            effectOpen.SetActive(true);
        }
        else
        {
            effectOpen.SetActive(false);
            effectclose.SetActive(true);
        }

        Debug.Log("user.userUrl = " + user.userUrl);
        if(user.loginControl == 1 ){
            Debug.Log(111);
            WXAvatarManager._instance.GetWxAvatar(int.Parse(user.Uid),wxAvatar,user.userUrl);
            wxAvatar.gameObject.SetActive(true);
        }
        else
        {
            Debug.Log(222);
            avatar.spriteName = user.avatarId.ToString();
        }
        
        IDLabel.text = "ID：" + user.Uid;
    }

    void ButtonClick(GameObject button)
    {
        if (button.name == "musicClose")
        {
            SoundModel._BGVolume = 0.6f;
            user.bgMusic = true;
            musicClose.SetActive(false);
            musicOpen.SetActive(true);
        }
        if (button.name == "musicOpen")
        {
            SoundModel._BGVolume = 0f;
            user.bgMusic = false;
            musicOpen.SetActive(false);
            musicClose.SetActive(true);  
        }
        if (button.name == "effectclose")
        {
            SoundModel.EffectVolume = 0.6f;
            user.effectMusic = true;
            effectclose.SetActive(false);
            effectOpen.SetActive(true);
        }
        if (button.name == "effectOpen")
        {
            SoundModel.EffectVolume = 0f;
            user.effectMusic = false;
            effectOpen.SetActive(false);
            effectclose.SetActive(true);
        }
        if (button.name == "BackBtn")
        {
            Destroy(gameObject);
        }
    }
}
